//
//  HRMainTableViewController.swift
//  weiBo
//
//  Created by helong on 16/7/9.
//  Copyright © 2016年 helong. All rights reserved.
//

import UIKit
import SVProgressHUD
class HRMainTableViewController: UITableViewController {
    //根据viewmodel中从沙河取出的对象是否为空判断登录状态
    var isLogin: Bool = HRUserAccountInfos.sharedUserAccount.isLogin
    var visitorView: HRVisitorView?
    
    override func loadView() {

        if isLogin{//首页已登录
            super.loadView()
        }else{//首页未登录
            
            visitorView = HRVisitorView()
            
            //添加注册按钮并绑定点击事件
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registButtonClicked")
            
            
            //添加登录按钮并绑定点击事件
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginButtonClicked")

            visitorView?.loginButtonClosure = {
                print("我是闭包传递过来的登录")
                self.loginButtonClicked()
            }
            visitorView?.registButtonClosure = {
                print("我是闭包传递过来的注册")
                self.registButtonClicked()
            }
            
            view = visitorView
        }

    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    //MARK: - 注册和登录按钮的点击事件
    /**
     注册按钮的点击事件
     */
    func registButtonClicked(){
        print("访客点击注册按钮")
        let loginPage = HRLoginPage()
        let nav = UINavigationController(rootViewController: loginPage)
        presentViewController(nav, animated: true, completion: nil)
        
    }
    /**
     登录按钮的点击事件
     */
    func loginButtonClicked(){
        print("访客点击登录按钮")
        let loginPage = HRLoginPage()
        let nav = UINavigationController(rootViewController: loginPage)
        presentViewController(nav, animated: true, completion: nil)
        
    }
}
